<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 浏览器导航</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            /* 明亮模式变量 */
            --bg-gradient-start: #667eea;
            --bg-gradient-end: #764ba2;
            --text-primary: #333;
            --text-secondary: #666;
            --container-bg: rgba(255, 255, 255, 0.95);
            --container-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            --input-bg: transparent;
            --input-border: #e0e0e0;
            --input-text: #333;
            --btn-bg: #667eea;
            --btn-hover: #5a6fd8;
            --btn-text: white;
            --link-color: #667eea;
            --error-bg: #ffebee;
            --error-text: #c62828;
            --error-border: #ffcdd2;
            --success-bg: #e8f5e8;
            --success-text: #2e7d32;
            --success-border: #c8e6c9;
        }

        @media (prefers-color-scheme: dark) {
            :root {
                /* 暗黑模式变量 */
                --bg-gradient-start: #1a1a2e;
                --bg-gradient-end: #16213e;
                --text-primary: #e0e0e0;
                --text-secondary: #b0b0b0;
                --container-bg: rgba(30, 30, 46, 0.95);
                --container-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
                --input-bg: rgba(255, 255, 255, 0.1);
                --input-border: #444;
                --input-text: #e0e0e0;
                --btn-bg: #667eea;
                --btn-hover: #5a6fd8;
                --btn-text: white;
                --link-color: #8a9eff;
                --error-bg: rgba(244, 67, 54, 0.2);
                --error-text: #ff8a80;
                --error-border: rgba(244, 67, 54, 0.3);
                --success-bg: rgba(76, 175, 80, 0.2);
                --success-text: #a5d6a7;
                --success-border: rgba(76, 175, 80, 0.3);
            }
        }

        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }

        .login-container {
            background: var(--container-bg);
            border-radius: 20px;
            padding: 40px;
            width: 100%;
            max-width: 400px;
            box-shadow: var(--container-shadow);
            transition: all 0.3s ease;
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header h1 {
            color: var(--text-primary);
            font-size: 2rem;
            margin-bottom: 10px;
        }

        .login-header p {
            color: var(--text-secondary);
            font-size: 1rem;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            color: var(--text-primary);
            font-weight: 500;
        }

        .form-group input {
            width: 100%;
            padding: 12px 15px;
            border: 2px solid var(--input-border);
            border-radius: 8px;
            font-size: 16px;
            outline: none;
            transition: border-color 0.3s ease;
            background: var(--input-bg);
            color: var(--input-text);
        }

        .form-group input:focus {
            border-color: var(--btn-bg);
        }

        .btn {
            width: 100%;
            padding: 12px;
            background: #667eea;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        .btn:hover {
            background: #5a6fd8;
        }

        .login-footer {
            text-align: center;
            margin-top: 20px;
        }

        .login-footer a {
            color: #667eea;
            text-decoration: none;
        }

        .login-footer a:hover {
            text-decoration: underline;
        }

        .message {
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 15px;
            text-align: center;
        }

        .message.error {
            background: #ffebee;
            color: #c62828;
            border: 1px solid #ffcdd2;
        }

        .message.success {
            background: #e8f5e8;
            color: #2e7d32;
            border: 1px solid #c8e6c9;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-header">
            <h1>欢迎回来</h1>
            <p>登录您的浏览器首页</p>
        </div>

        <div id="message"></div>

        <form id="loginForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" required>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" required>
            </div>
            
            <button type="submit" class="btn">登录</button>
        </form>

        <div class="login-footer">
            <p>还没有账号？<a href="/user/register">立即注册</a></p>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const data = Object.fromEntries(formData);
            
            fetch('/user/dologin', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(data)
            })
            .then(response => response.json())
            .then(result => {
                const messageDiv = document.getElementById('message');
                if (result.code === 200) {
                    messageDiv.innerHTML = `<div class="message success">${result.message}</div>`;
                    setTimeout(() => {
                        window.location.href = '/';
                    }, 1000);
                } else {
                    messageDiv.innerHTML = `<div class="message error">${result.message}</div>`;
                }
            })
            .catch(error => {
                console.error('Error:', error);
                document.getElementById('message').innerHTML = '<div class="message error">登录失败，请稍后重试</div>';
            });
        });
    </script>
</body>
</html>